package com.qiantu.phone.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.hjq.base.DensityUtils;
import com.hjq.base.FragmentPagerAdapter;
import com.hjq.http.listener.HttpCallback;
import com.lxj.xpopup.XPopup;
import com.qiantu.api.entity.BeforeAfterTimesBean;
import com.qiantu.api.entity.TimesBean;
import com.qiantu.api.http.LLHttpManager;
import com.qiantu.api.http.model.HttpData;
import com.qiantu.phone.R;
import com.qiantu.phone.action.StatusAction;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.app.AppFragment;
import com.qiantu.phone.app.TitleBarFragment;
import com.qiantu.phone.event.RefreshRecommendSceneSwitchEvent;
import com.qiantu.phone.ui.activity.AddConditionActivity;
import com.qiantu.phone.ui.activity.EditSceneActivityNew;
import com.qiantu.phone.ui.activity.EditTimeActivity;
import com.qiantu.phone.ui.activity.SceneManageActivity;
import com.qiantu.phone.ui.activity.SceneOrderActivity;
import com.qiantu.phone.ui.adapter.TimesAdapter;
import com.qiantu.phone.ui.dialog.OptionDialog;
import com.qiantu.phone.utils.SPUtils;
import com.qiantu.phone.widget.StatusLayout;
import com.qiantu.phone.widget.StickyItemDecoration;
import com.qiantu.phone.widget.ViewPagerIndicator;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;

/**
 * time   : 2021/12/22
 */
public final class TimeFragment extends TitleBarFragment<AppActivity> {
    private ViewPager viewPager;
    private View btnAdd;
    private int currentItem;

    public TimeFragment() {
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        if(savedInstanceState != null){
            currentItem = savedInstanceState.getInt("currentItem", 0);
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_tabbar_time;
    }

    @Override
    protected void initView() {
        viewPager = findViewById(R.id.view_pager);
        btnAdd = findViewById(R.id.btn_add);
        setOnClickListener(btnAdd);
        initViewPager();
    }

    private void initViewPager() {
        FragmentPagerAdapter<Fragment> mPagerAdapter = new FragmentPagerAdapter<>(this);
        mPagerAdapter.addFragment(TimeFragmentNew.newInstance());
        viewPager.setAdapter(mPagerAdapter);
    }
    @Override
    public void onClick(View view) {
        if (view == btnAdd){
            startActivity(EditTimeActivity.class);
        }
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        if(viewPager != null){
            outState.putInt("currentItem", viewPager.getCurrentItem());
        }
    }

    @Override
    protected void initData() {

    }

    public ViewPager getViewPager() {
        return viewPager;
    }

    @Override
    public boolean isStatusBarEnabled() {
        // 使用沉浸式状态栏
        return true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if(!isHidden()){
            getAttachActivity().getStatusBarConfig().statusBarDarkFont(AppApplication.getInstance().getThemeBoolean(R.attr.statusBarChangeIsDarkFont)).init();
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!isHidden()){
            getAttachActivity().getStatusBarConfig().statusBarDarkFont(AppApplication.getInstance().getThemeBoolean(R.attr.statusBarChangeIsDarkFont)).init();
        }
    }
}